
;-------------------------------------------
; flde v0.1 Fasmlab Disassembler Engine 32b
; BSD License
; Copyright (c) 2009, Marc Rainer Kranz
; All rights reserved
;-------------------------------------------

db 66h, 6Ch, 64h, 65h, 20h, 76h, 30h, 2Eh, 31h, 20h, 46h, 61h, 73h, 6Dh, 6Ch, 61h 
db 62h, 20h, 44h, 69h, 73h, 61h, 73h, 73h, 65h, 6Dh, 62h, 6Ch, 65h, 72h, 20h, 45h 
db 6Eh, 67h, 69h, 6Eh, 65h, 20h, 33h, 32h, 62h, 00h, 42h, 53h, 44h, 20h, 4Ch, 69h 
db 63h, 65h, 6Eh, 73h, 65h, 00h, 43h, 6Fh, 70h, 79h, 72h, 69h, 67h, 68h, 74h, 20h 
db 28h, 63h, 29h, 20h, 32h, 30h, 30h, 39h, 2Ch, 20h, 4Dh, 61h, 72h, 63h, 20h, 52h 
db 61h, 69h, 6Eh, 65h, 72h, 20h, 4Bh, 72h, 61h, 6Eh, 7Ah, 00h, 41h, 6Ch, 6Ch, 20h
db 72h, 69h, 67h, 68h, 74h, 73h, 20h, 72h, 65h, 73h, 65h, 72h, 76h, 65h, 64h, 00h

;----------------------
;26-ES 0010'0110b
;2E-CS 0010'1110b
;36-SS 0011'0110b
;64-FS 0110'0100b
;65-GS 0110'0101b
;MASK  0X1X'X1XXb
;----------------------
;0F 0000'1111b
;66 0110'0110b
;67 0110'0111b
;F2 1111'0010b
;F3 1111'0011b
;MASK XXXX'XX1X
;-----------------------

;RET EDX:
; PREFIXING(1) 
; INSTR(1) 
; MOD=DH 
; LEN(1)=DL

;RET ECX = len
;RET EAX = pointer to instruction

NULL equ 0

PREF_0F	equ 0000'0001b
PREF_66	equ 0000'0010b
PREF_67	equ 0000'0100b
PREF_F2	equ 0000'1000b
PREF_F3	equ 0001'0000b

SEG_26	equ 001'00000b
SEG_2E	equ 010'00000b
SEG_36	equ 011'00000b
SEG_3E	equ 100'00000b
SEG_64	equ 101'00000b
SEG_65	equ 110'00000b

SIB		equ 1000b
D1		equ 0001b
D2		equ 0010b
D3		equ 0011b
D4		equ 0100b

INSTR_PURE 	equ 0000b
INSTR_MOD  	equ 1000b

INSTR_LEN1 	equ INSTR_PURE or 0001b
INSTR_LEN2	equ INSTR_PURE or 0010b
INSTR_LEN3	equ INSTR_PURE or 0011b
INSTR_LEN4	equ INSTR_PURE or 0100b
INSTR_LEN5	equ INSTR_PURE or 0101b
INSTR_LEN6	equ INSTR_PURE or 0110b
INSTR_LEN7	equ INSTR_PURE or 0111b

INSTR_MOD1 	equ INSTR_MOD or 0001b
INSTR_MOD2	equ INSTR_MOD or 0010b
INSTR_MOD3	equ INSTR_MOD or 0011b
INSTR_MOD4	equ INSTR_MOD or 0100b
INSTR_MOD5	equ INSTR_MOD or 0101b
INSTR_MOD6	equ INSTR_MOD or 0110b
INSTR_MOD7	equ INSTR_MOD or 0111b

macro @lpack labname,argformat,argbits,[argvalue]{
	restbits = 8
	tmpvalue = 0
	tmpbits = restbits
	tmptype equ 0FFh
	common
	label labname
	match =dw,argformat\{	
		restbits = restbits shl 1	
		tmptype equ 0FFFFh
	\}
	match =dd,argformat\{	
	restbits = restbits shl 2	
			tmptype equ 0FFFFFFFFh
	\}
	forward
	tmpvalue = tmpvalue shl argbits
	restbits = restbits - argbits

	if restbits = 0
		tmpvalue = tmpvalue or argvalue
		argformat tmpvalue
		tmpvalue = 0
		restbits = tmpbits
	else
	tmpvalue = tmpvalue or argvalue
	end if
}

;description L/H nibble:
;---------- LEN LEN DISP SIB --------
;------------0---0---0----0----------
@lpack table1,db,4,\
	INSTR_MOD,	INSTR_MOD,\		;0
	INSTR_MOD,	INSTR_MOD,\
	INSTR_LEN1,	INSTR_LEN4,\
	INSTR_PURE,	INSTR_PURE,\	
	INSTR_MOD,	INSTR_MOD,\		;8
	INSTR_MOD,	INSTR_MOD,\
	INSTR_LEN1,	INSTR_LEN4,\
	INSTR_PURE,	0,\  ;0Fh
	INSTR_MOD,	INSTR_MOD,\		;10h ADC
	INSTR_MOD,	INSTR_MOD,\
	INSTR_LEN1,	INSTR_LEN4,\
	INSTR_PURE,	INSTR_PURE,\
	INSTR_MOD,	INSTR_MOD,\		;18h SBB
	INSTR_MOD,	INSTR_MOD,\
	INSTR_LEN1,	INSTR_LEN4,\
	INSTR_PURE,	INSTR_PURE,\	
	INSTR_MOD,	INSTR_MOD,\		;20h AND
	INSTR_MOD,	INSTR_MOD,\
	INSTR_LEN1,	INSTR_LEN4,\
	INSTR_PURE,	INSTR_PURE,\
	INSTR_MOD,	INSTR_MOD,\		;28h SUB
	INSTR_MOD,	INSTR_MOD,\
	INSTR_LEN1,	INSTR_LEN4,\
	INSTR_PURE,	INSTR_PURE,\
	INSTR_MOD,	INSTR_MOD,\		;30h XOR
	INSTR_MOD,	INSTR_MOD,\
	INSTR_LEN1,	INSTR_LEN4,\
	INSTR_PURE,	INSTR_PURE,\
	INSTR_MOD,	INSTR_MOD,\		;38h CMP
	INSTR_MOD,	INSTR_MOD,\
	INSTR_LEN1,	INSTR_LEN4,\
	INSTR_PURE,	INSTR_PURE,\	;3E Prefix /3F AAS
	INSTR_PURE,	INSTR_PURE,\	;40h INC EAX
	INSTR_PURE,	INSTR_PURE,\	
	INSTR_PURE,	INSTR_PURE,\	
	INSTR_PURE,	INSTR_PURE,\	
	INSTR_PURE,	INSTR_PURE,\	;48 DEC	
	INSTR_PURE,	INSTR_PURE,\	
	INSTR_PURE,	INSTR_PURE,\	
	INSTR_PURE,	INSTR_PURE,\
	INSTR_PURE,	INSTR_PURE,\	;50h PUSH
	INSTR_PURE,	INSTR_PURE,\
	INSTR_PURE,	INSTR_PURE,\
	INSTR_PURE,	INSTR_PURE,\
	INSTR_PURE,	INSTR_PURE,\	;58h POP
	INSTR_PURE,	INSTR_PURE,\
	INSTR_PURE,	INSTR_PURE,\
	INSTR_PURE,	INSTR_PURE,\
	INSTR_PURE,	INSTR_PURE,\  ;60h PUSHA
	INSTR_MOD,	INSTR_MOD,\
					0,	0,\						;64/65 PREFIXES FS/GS
					0,	0,\  					;66/67 prefix address
	INSTR_LEN4,	INSTR_MOD4,\	;PUSH imm / IMUL imm
	INSTR_LEN1,	INSTR_MOD1,\	;PUSH imm8 / IMUL imm8
	INSTR_PURE,	INSTR_PURE,\
	INSTR_PURE,	INSTR_PURE,\
	INSTR_LEN1,	INSTR_LEN1,\	;70h JXX
	INSTR_LEN1,	INSTR_LEN1,\
	INSTR_LEN1,	INSTR_LEN1,\
	INSTR_LEN1,	INSTR_LEN1,\
	INSTR_LEN1,	INSTR_LEN1,\
	INSTR_LEN1,	INSTR_LEN1,\
	INSTR_LEN1,	INSTR_LEN1,\
	INSTR_LEN1,	INSTR_LEN1,\
	INSTR_MOD1,	INSTR_MOD4,\	;80h ADD
	INSTR_MOD1,	INSTR_MOD1,\	;82h
	INSTR_MOD,	INSTR_MOD,\
	INSTR_MOD,	INSTR_MOD,\
	INSTR_MOD,	INSTR_MOD,\
	INSTR_MOD,	INSTR_MOD,\
	INSTR_MOD,	INSTR_MOD,\
	INSTR_MOD,	INSTR_MOD,\
	INSTR_PURE,	INSTR_PURE,\	;90h NOP
	INSTR_PURE,	INSTR_PURE,\		
	INSTR_PURE,	INSTR_PURE,\		
	INSTR_PURE,	INSTR_PURE,\		
	INSTR_PURE,	INSTR_PURE,\
	INSTR_LEN6,	INSTR_MOD,\		;9Ah CALL / FPU ;<----------
	INSTR_PURE,	INSTR_PURE,\		
	INSTR_PURE,	INSTR_PURE,\
	INSTR_LEN1,	INSTR_LEN4,\	;A0 MOV
	INSTR_LEN1,	INSTR_LEN4,\
	INSTR_PURE,	INSTR_PURE,\		
	INSTR_PURE,	INSTR_PURE,\
	INSTR_LEN1,	INSTR_LEN4,\
	INSTR_PURE,	INSTR_PURE,\	;AA STOSB	
	INSTR_PURE,	INSTR_PURE,\
	INSTR_PURE,	INSTR_PURE,\
	INSTR_LEN1,	INSTR_LEN1,\	;B0 MOV
	INSTR_LEN1,	INSTR_LEN1,\
	INSTR_LEN1,	INSTR_LEN1,\
	INSTR_LEN1,	INSTR_LEN1,\
	INSTR_LEN4,	INSTR_LEN4,\	;B8
	INSTR_LEN4,	INSTR_LEN4,\	;
	INSTR_LEN4,	INSTR_LEN4,\	;
	INSTR_LEN4,	INSTR_LEN4,\	;
	INSTR_MOD1,	INSTR_MOD1,\	;C0
	INSTR_LEN2,	INSTR_PURE,\	;RETN /RET
	INSTR_MOD,	INSTR_MOD,\
	INSTR_MOD1,	INSTR_MOD4,\	;C6
	INSTR_LEN3,	INSTR_PURE,\	;ENTER IMM16,IMM8
	INSTR_LEN2,	INSTR_PURE,\	;CA
	INSTR_PURE,	INSTR_LEN1,\
	INSTR_PURE,	INSTR_PURE,\
	INSTR_MOD,	INSTR_MOD,\		;D0 ROL
	INSTR_MOD,	INSTR_MOD,\
	INSTR_LEN1,	INSTR_LEN1,\
	INSTR_PURE,	INSTR_PURE,\
	INSTR_MOD,	INSTR_MOD,\		;D8 FADD	
	INSTR_MOD,	INSTR_MOD,\
	INSTR_MOD,	INSTR_MOD,\
	INSTR_MOD,	INSTR_MOD,\
	INSTR_LEN1,	INSTR_LEN1,\	;E0 LOPPNZ
	INSTR_LEN1,	INSTR_LEN1,\
	INSTR_LEN1,	INSTR_LEN1,\
	INSTR_LEN1,	INSTR_LEN1,\
	INSTR_LEN4,	INSTR_LEN4,\	;B8
	INSTR_LEN4,	INSTR_LEN1,\	;EA FAR ABSOLUTE JMP
	INSTR_PURE,	INSTR_PURE,\		
	INSTR_PURE,	INSTR_PURE,\		
	INSTR_PURE,	INSTR_PURE,\	;F0	LOCK
	INSTR_PURE,	INSTR_PURE,\	;F2 /F3 REPNZ/REP/
	INSTR_PURE,	INSTR_PURE,\
	INSTR_MOD,	INSTR_MOD,\
	INSTR_PURE,	INSTR_PURE,\		
	INSTR_PURE,	INSTR_PURE,\		
	INSTR_PURE,	INSTR_PURE,\		
	INSTR_MOD,	INSTR_MOD

@lpack table2,db,4,\
	INSTR_MOD,\
	INSTR_MOD,\		;<---01 review
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_PURE,\
	INSTR_PURE,\
	INSTR_PURE,\
	INSTR_PURE,\	
	INSTR_PURE,\	;8
	INSTR_PURE,\	
	0,\
	INSTR_PURE,\	;0B
	0,\
	INSTR_MOD,\
	INSTR_PURE,\
	INSTR_MOD1,\	;0F
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\		;12 <-- rev
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	0,\						;19h
	0,\
	0,\
	0,\
	0,\
	0,\
	0,\
	INSTR_MOD,\		;20h
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	0,\
	INSTR_MOD,\		;26h
	0,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_PURE,\	;30h
	INSTR_PURE,\
	INSTR_PURE,\
	INSTR_PURE,\
	INSTR_PURE,\
	INSTR_PURE,\
	INSTR_MOD,\		;36h
	INSTR_MOD,\
	INSTR_MOD,\
	0,\
	0,\
	0,\
	INSTR_MOD,\		;3Ch
	0,\
	0,\
	0,\
	INSTR_MOD,\		;40h
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\		;50h
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	IN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	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\		;B0
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\		;B5
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD4,\	;B8
	INSTR_PURE,\
	INSTR_MOD1,\
	INSTR_MOD,\		;BB
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD1,\	;C2
	INSTR_MOD,\
	INSTR_MOD1,\	;C4
	INSTR_MOD1,\
	INSTR_MOD1,\
	INSTR_MOD,\		;C7
	INSTR_PURE,\
	INSTR_PURE,\
	INSTR_PURE,\
	INSTR_PURE,\
	INSTR_PURE,\
	INSTR_PURE,\
	INSTR_PURE,\
	INSTR_PURE,\
	0,\						;D0
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	0,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	0,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	0,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_MOD,\	;FCh
	INSTR_MOD,\
	INSTR_MOD,\
	INSTR_PURE

;1= byte to add
table66		db 71h,72h,073h,0C4h,0C5h,0C6h ;6+2+1fixed byte
tableF2F3 db 70h,0C2h
table9B		db 0DBh,0DFh	;1 fixed more byte
align 4

@lpack mod32_table,db,4,\
	NULL,NULL,\	;;MOD 00
	NULL,NULL,\
	SIB,D4,\
	NULL,NULL,\
	D1,D1,\			;;MOD 01
	D1,D1,\
	SIB or D1,D1,\
	D1,D1,\
	D4,D4,\		;;MOD 10
	D4,D4,\
	SIB or D4,D4,\
	D4,D4,\
	NULL,NULL,\	;;MOD 11
	NULL,NULL,\
	NULL,NULL,\
	NULL,NULL
